package com.example.start.jwt;

import com.example.dmcommom.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import static org.springframework.http.HttpStatus.UNAUTHORIZED;

@RestControllerAdvice
public class ErrorController {

	@ResponseStatus(UNAUTHORIZED)
	@ExceptionHandler(value = AuthException.class)
	public ResponseResult<T> error(AuthException e) {
		return ResponseResult.error(UNAUTHORIZED.value(), e.getMessage(), null);
	}

	//用户token权限
	@ResponseStatus(UNAUTHORIZED)
	@ExceptionHandler(value = TokenAuthException.class)
	public ResponseResult<T> error(TokenAuthException e) {
		return ResponseResult.error(UNAUTHORIZED.value(), e.getMessage(), null);
	}

	//用户角色权限
	@ResponseStatus(UNAUTHORIZED)
	@ExceptionHandler(value = PermsException.class)
	public ResponseResult<T> error(PermsException e) {
		return ResponseResult.error(UNAUTHORIZED.value(), e.getMessage(), null);
	}

	//用户按钮权限
	@ResponseStatus(UNAUTHORIZED)
	@ExceptionHandler(value = BtnAuthException.class)
	public ResponseResult<T> error(BtnAuthException e) {

		return ResponseResult.error(UNAUTHORIZED.value(), e.getMessage(), null);
	}

	//用户按钮权限
	@ResponseStatus(UNAUTHORIZED)
	@ExceptionHandler(value = RedirectPageException.class)
	public ResponseResult<T> error(RedirectPageException e) {

		return ResponseResult.error(302, e.getMessage(), null);
	}

}
